import 'package:flutter/material.dart'; // fim简便写法
import 'res/listData.dart';

void main() {
  runApp(MyApp());
}

// 基本结构
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: Text('container  text')),
        body: HomeContent(),
      ),
    );
  }
}

// 01 statelessW 简写出现下面这些  无状态组件
// class HomeContent extends StatelessWidget {
//   int countNum = 1;
//   @override
//   Widget build(BuildContext context) {
// return Column(
//   children: <Widget>[
//     SizedBox(height: 200),
//     Text("${this.countNum}"),
//     SizedBox(height: 20),
//     RaisedButton(
//         child: Text('按钮'),
//         onPressed: () {
//           print(this.countNum);
//         })
//   ],
// );
//   }
// }

// 02 有状态的
// class HomeContent extends StatefulWidget {
//   HomeContent({Key key}) : super(key: key);

//   @override
//   _HomeContentState createState() => _HomeContentState();
// }

// class _HomeContentState extends State<HomeContent> {
//   int countNum = 1;
//   @override
//   Widget build(BuildContext context) {
//     return Column(
//       children: <Widget>[
//         SizedBox(height: 200),
//         Text("${this.countNum}"),
//         SizedBox(height: 20),
//         RaisedButton(
//             child: Text('按钮'),
//             onPressed: () {
//               setState(() {
//                 this.countNum++;
//                 print(this.countNum);
//               });
//             })
//       ],
//     );
//   }
// }


// 03 
class HomeContent extends StatefulWidget {
  HomeContent({Key key}) : super(key: key);

  @override
  _HomeContentState createState() => _HomeContentState();
}

class _HomeContentState extends State<HomeContent> {
  List list = new List();
  @override
  Widget build(BuildContext context) {
    return ListView(
      children: <Widget>[
        Column(
          children: this.list.map((value){
            return ListTile(
              title: Text(value),
            );
          }).toList(),
        ),
        SizedBox(height: 20,),
        RaisedButton(
          child: Text("按钮"),
          onPressed: (){
            setState(() {
              this.list.add("val1");
              this.list.add("val2");
            });
          },
        )
      ],
    );
  }
}
